package xyz.k1998.springboot.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.k1998.springboot.bean.Department;
import xyz.k1998.springboot.mapper.DepartmentMapper;

import java.util.List;

@RequestMapping("dept/")
@RestController
public class DeptController {

    @Autowired
    DepartmentMapper departmentMapper;

    @GetMapping("all")
    public List<Department> getAllUsers() {
        List<Department> kkk = (List<Department>) departmentMapper.findAll();
        return kkk;

    }

    @GetMapping("/{id}")
    public Department getDepartment(@PathVariable("id") Integer id) {
        return departmentMapper.getDeptById(id);
    }

    @GetMapping("/")
    public Department insertDept(Department department) {
        departmentMapper.insertDeptById(department);
        return department;
    }

    @GetMapping(value = "/delete/{id}")
    public String deleteDept(@PathVariable("id") Integer id) {
        departmentMapper.deleteDeptById(id);
        return id + ":已成功删除";
    }



}
